package org.skatiger.jrove.spring.controllers;

import java.util.Arrays;
import java.util.List;

import org.skatiger.jrove.spring.Losted;
import org.skatiger.jrove.spring.models.PersonForm;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class PersonFormController {
    @RequestMapping(value = "/person/form", method = RequestMethod.GET)
    public ModelAndView personForm() {

        ModelAndView mv = new ModelAndView("/person", "person",
                new PersonForm());
        mv.addObject("chpwd2Items", new Boolean[] { Boolean.TRUE,
                                                   Boolean.FALSE });
        List<Losted> list = Arrays.asList(Losted.values());
        mv.addObject("_losteds", list);

        return mv;
    }

    @RequestMapping(value = "/person", method = RequestMethod.POST)
    public String createPerson(PersonForm person, BindingResult result) {
        System.out.println(person);
        return "redirect:/person/form";
    }

}
